;;representing vectors in the plane

(define (make-vector x y) (cons x y))
(define (xcor p) (car p))
(define (ycor p) (cdr p))
 
;;representing line segments

(define (make-seg p q) (cons p q))
(define (seg-start s) (car s))
(define (seg-end s) (cdr s))
 
(define (midpoint s)
  (let ((a (seg-start s))
        (b (seg-end s)))
    (make-vector
     (average (xcor a) (xcor b))
     (average (ycor a) (ycor b)))))
 
(define (length s)
  (let
      ((dx (- (xcor (seg-end s))
              (xcor (seg-start s))))
       (dy (- (ycor (seg-end s))
              (ycor (seg-start s)))))
    (sqrt (+ (square dx)
             (square dy)))))


;;what we built is a layered system
;;;          segments
;;;
;;;---------------------------
;;;make-seg seg-start seg-end
;;;----------------------------
;;;
;;;           vectors
;;;
;;;----------------------------
;;;make-vector xcor ycor
;;;----------------------------
;;;
;;;           pairs


;;you don't see any data in here, what you see is a lambda
(define (cons a b)
  (lambda (pick)
    (cond ((= pick 1) a)
          ((= pick 2) b))))
 
(define (car x) (x 1))
(define (cdr x) (x 2))

(car (cons  2 3))
(cdr (cons  2 3))